package com.mdxl.layer_cj.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class LoginController {
    @GetMapping(value = "/")
    public String toTurn(){
        return "redirect:/login";
    }
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String login(){
        return "login";
    }
    @GetMapping(value = "/success")
    public String success(){
        return "success";
    }


    @PostMapping(value = "/userLogin")
    @ResponseBody
    public String userLogin(HttpServletRequest request, HttpServletResponse response){

        JSONObject result  = new JSONObject();
        String userName    = ServletRequestUtils.getStringParameter(request,"username",null);
        String password    = ServletRequestUtils.getStringParameter(request,"password",null);
        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
            result.put("code","1001");
            result.put("msg","用户名或密码为空");
            return result.toString();
        }
        result.put("code","1000");
        result.put("msg","chengong");
        System.out.println(result.toJSONString());

        return result.toJSONString();
    }
}
